
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/matrices/expressions.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:19 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Matrix Expressions &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="expressions.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Number Theory" href="../ntheory.html" />
    <link rel="prev" title="Immutable Matrices" href="immutablematrices.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../ntheory.html" title="Number Theory"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="immutablematrices.html" title="Immutable Matrices"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Matrices</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Matrix Expressions</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.matrices.expressions">
<span id="matrix-expressions"></span><h1>Matrix Expressions<a class="headerlink" href="#module-sympy.matrices.expressions" title="Permalink to this headline">¶</a></h1>
<p>The Matrix expression module allows users to write down statements like</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">X</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">X</span><span class="p">)</span><span class="o">.</span><span class="n">I</span><span class="o">*</span><span class="n">Y</span>
<span class="go">X**(-1)*X.T**(-1)*Y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[X[0, 0], X[0, 1], X[0, 2]],</span>
<span class="go">[X[1, 0], X[1, 1], X[1, 2]],</span>
<span class="go">[X[2, 0], X[2, 1], X[2, 2]]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">X</span><span class="o">*</span><span class="n">Y</span><span class="p">)[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="go">X[1, 0]*Y[0, 2] + X[1, 1]*Y[1, 2] + X[1, 2]*Y[2, 2]</span>
</pre></div>
</div>
<p>where <code class="docutils literal notranslate"><span class="pre">X</span></code> and <code class="docutils literal notranslate"><span class="pre">Y</span></code> are <a class="reference internal" href="#sympy.matrices.expressions.MatrixSymbol" title="sympy.matrices.expressions.MatrixSymbol"><code class="xref py py-class docutils literal notranslate"><span class="pre">MatrixSymbol</span></code></a>’s rather than scalar symbols.</p>
<section id="matrix-expressions-core-reference">
<h2>Matrix Expressions Core Reference<a class="headerlink" href="#matrix-expressions-core-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatrixExpr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L38-L606"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr" title="Permalink to this definition">¶</a></dt>
<dd><p>Superclass for Matrix Expressions</p>
<p>MatrixExprs represent abstract matrices, linear transformations represented
within a particular basis.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">A</span><span class="p">)</span><span class="o">.</span><span class="n">I</span> <span class="o">*</span> <span class="n">A</span> <span class="o">*</span> <span class="n">y</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.expressions.MatrixSymbol" title="sympy.matrices.expressions.MatrixSymbol"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatrixSymbol</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.MatAdd" title="sympy.matrices.expressions.MatAdd"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatAdd</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.MatMul" title="sympy.matrices.expressions.MatMul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MatMul</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.Transpose" title="sympy.matrices.expressions.Transpose"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Transpose</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.Inverse" title="sympy.matrices.expressions.Inverse"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Inverse</span></code></a></p>
</div>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr.T">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">T</span></span><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr.T" title="Permalink to this definition">¶</a></dt>
<dd><p>Matrix transposition</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr.as_coeff_Mul">
<span class="sig-name descname"><span class="pre">as_coeff_Mul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rational</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L242-L244"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr.as_coeff_Mul" title="Permalink to this definition">¶</a></dt>
<dd><p>Efficiently extract the coefficient of a product.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr.as_explicit">
<span class="sig-name descname"><span class="pre">as_explicit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L313-L345"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr.as_explicit" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dense Matrix with elements represented explicitly</p>
<p>Returns an object of type ImmutableDenseMatrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Identity</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">Identity</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span>
<span class="go">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.matrices.expressions.MatrixExpr.as_mutable" title="sympy.matrices.expressions.MatrixExpr.as_mutable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_mutable</span></code></a></dt><dd><p>returns mutable Matrix type</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr.as_mutable">
<span class="sig-name descname"><span class="pre">as_mutable</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L347-L370"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr.as_mutable" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dense, mutable matrix with elements represented explicitly</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Identity</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">Identity</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span>
<span class="go">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(3, 3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">.</span><span class="n">as_mutable</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.matrices.expressions.MatrixExpr.as_explicit" title="sympy.matrices.expressions.MatrixExpr.as_explicit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">as_explicit</span></code></a></dt><dd><p>returns ImmutableDenseMatrix</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr.equals">
<span class="sig-name descname"><span class="pre">equals</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L380-L389"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr.equals" title="Permalink to this definition">¶</a></dt>
<dd><p>Test elementwise equality between matrices, potentially of different
types</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Identity</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Identity</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixExpr.from_index_summation">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">from_index_summation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">first_index</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">last_index</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dimensions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L397-L602"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixExpr.from_index_summation" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse expression of matrices with explicitly summed indices into a
matrix expression without indices, if possible.</p>
<p>This transformation expressed in mathematical notation:</p>
<p><span class="math notranslate nohighlight">\(\sum_{j=0}^{N-1} A_{i,j} B_{j,k} \Longrightarrow \mathbf{A}\cdot \mathbf{B}\)</span></p>
<p>Optional parameter <code class="docutils literal notranslate"><span class="pre">first_index</span></code>: specify which free index to use as
the index starting the expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">MatrixExpr</span><span class="p">,</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">N</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s2">&quot;B&quot;</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">B</span><span class="p">[</span><span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">],</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MatrixExpr</span><span class="o">.</span><span class="n">from_index_summation</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">A*B</span>
</pre></div>
</div>
<p>Transposition is detected:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">A</span><span class="p">[</span><span class="n">j</span><span class="p">,</span> <span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">B</span><span class="p">[</span><span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">],</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MatrixExpr</span><span class="o">.</span><span class="n">from_index_summation</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">A.T*B</span>
</pre></div>
</div>
<p>Detect the trace:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MatrixExpr</span><span class="o">.</span><span class="n">from_index_summation</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">Trace(A)</span>
</pre></div>
</div>
<p>More complicated expressions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">B</span><span class="p">[</span><span class="n">k</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">A</span><span class="p">[</span><span class="n">l</span><span class="p">,</span> <span class="n">k</span><span class="p">],</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MatrixExpr</span><span class="o">.</span><span class="n">from_index_summation</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">A*B.T*A.T</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixSymbol">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatrixSymbol</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matexpr.py#L776-L842"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixSymbol" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic representation of a Matrix object</p>
<p>Creates a SymPy Symbol to represent a Matrix. This matrix has a shape and
can be included in Matrix Expressions</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Identity</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="c1"># A 3 by 4 Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># A 4 by 3 Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(3, 4)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span><span class="o">*</span><span class="n">A</span><span class="o">*</span><span class="n">B</span> <span class="o">+</span> <span class="n">Identity</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">I + 2*A*B</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatAdd">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatAdd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">check</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_sympify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matadd.py#L17-L87"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatAdd" title="Permalink to this definition">¶</a></dt>
<dd><p>A Sum of Matrix Expressions</p>
<p>MatAdd inherits from and operates like SymPy Add</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatAdd</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MatAdd</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">)</span>
<span class="go">A + B + C</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatMul">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatMul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">check</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_sympify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matmul.py#L19-L209"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatMul" title="Permalink to this definition">¶</a></dt>
<dd><p>A product of matrix expressions</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatMul</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MatMul</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">)</span>
<span class="go">A*B*C</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatPow">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatPow</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">base</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exp</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/matpow.py#L9-L141"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatPow" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.HadamardProduct">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">HadamardProduct</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">evaluate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">check</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/hadamard.py#L37-L146"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.HadamardProduct" title="Permalink to this definition">¶</a></dt>
<dd><p>Elementwise product of matrix expressions</p>
<p class="rubric">Examples</p>
<p>Hadamard product for matrix symbols:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">hadamard_product</span><span class="p">,</span> <span class="n">HadamardProduct</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">hadamard_product</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">),</span> <span class="n">HadamardProduct</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This is a symbolic object that simply stores its argument without
evaluating it. To actually compute the product, use the function
<code class="docutils literal notranslate"><span class="pre">hadamard_product()</span></code> or <code class="docutils literal notranslate"><span class="pre">HadamardProduct.doit</span></code></p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.HadamardPower">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">HadamardPower</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">base</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exp</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/hadamard.py#L309-L465"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.HadamardPower" title="Permalink to this definition">¶</a></dt>
<dd><p>Elementwise power of matrix expressions</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>base</strong> : scalar or matrix</p>
<p><strong>exp</strong> : scalar or matrix</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>There are four definitions for the hadamard power which can be used.
Let’s consider <span class="math notranslate nohighlight">\(A, B\)</span> as <span class="math notranslate nohighlight">\((m, n)\)</span> matrices, and <span class="math notranslate nohighlight">\(a, b\)</span> as scalars.</p>
<p>Matrix raised to a scalar exponent:</p>
<div class="math notranslate nohighlight">
\[\begin{split}A^{\circ b} = \begin{bmatrix}
A_{0, 0}^b   &amp; A_{0, 1}^b   &amp; \cdots &amp; A_{0, n-1}^b   \\
A_{1, 0}^b   &amp; A_{1, 1}^b   &amp; \cdots &amp; A_{1, n-1}^b   \\
\vdots       &amp; \vdots       &amp; \ddots &amp; \vdots         \\
A_{m-1, 0}^b &amp; A_{m-1, 1}^b &amp; \cdots &amp; A_{m-1, n-1}^b
\end{bmatrix}\end{split}\]</div>
<p>Scalar raised to a matrix exponent:</p>
<div class="math notranslate nohighlight">
\[\begin{split}a^{\circ B} = \begin{bmatrix}
a^{B_{0, 0}}   &amp; a^{B_{0, 1}}   &amp; \cdots &amp; a^{B_{0, n-1}}   \\
a^{B_{1, 0}}   &amp; a^{B_{1, 1}}   &amp; \cdots &amp; a^{B_{1, n-1}}   \\
\vdots         &amp; \vdots         &amp; \ddots &amp; \vdots           \\
a^{B_{m-1, 0}} &amp; a^{B_{m-1, 1}} &amp; \cdots &amp; a^{B_{m-1, n-1}}
\end{bmatrix}\end{split}\]</div>
<p>Matrix raised to a matrix exponent:</p>
<div class="math notranslate nohighlight">
\[\begin{split}A^{\circ B} = \begin{bmatrix}
A_{0, 0}^{B_{0, 0}}     &amp; A_{0, 1}^{B_{0, 1}}     &amp;
\cdots &amp; A_{0, n-1}^{B_{0, n-1}}     \\
A_{1, 0}^{B_{1, 0}}     &amp; A_{1, 1}^{B_{1, 1}}     &amp;
\cdots &amp; A_{1, n-1}^{B_{1, n-1}}     \\
\vdots                  &amp; \vdots                  &amp;
\ddots &amp; \vdots                      \\
A_{m-1, 0}^{B_{m-1, 0}} &amp; A_{m-1, 1}^{B_{m-1, 1}} &amp;
\cdots &amp; A_{m-1, n-1}^{B_{m-1, n-1}}
\end{bmatrix}\end{split}\]</div>
<p>Scalar raised to a scalar exponent:</p>
<div class="math notranslate nohighlight">
\[a^{\circ b} = a^b\]</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.Inverse">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">Inverse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mat</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-</span> <span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/inverse.py#L8-L76"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.Inverse" title="Permalink to this definition">¶</a></dt>
<dd><p>The multiplicative inverse of a matrix expression</p>
<p>This is a symbolic object that simply stores its argument without
evaluating it. To actually compute the inverse, use the <code class="docutils literal notranslate"><span class="pre">.inverse()</span></code>
method of matrices.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Inverse</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Inverse</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">A**(-1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">inverse</span><span class="p">()</span> <span class="o">==</span> <span class="n">Inverse</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="p">)</span><span class="o">.</span><span class="n">inverse</span><span class="p">()</span>
<span class="go">B**(-1)*A**(-1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Inverse</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="p">)</span>
<span class="go">(A*B)**(-1)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.Transpose">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">Transpose</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/transpose.py#L7-L79"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.Transpose" title="Permalink to this definition">¶</a></dt>
<dd><p>The transpose of a matrix expression.</p>
<p>This is a symbolic object that simply stores its argument without
evaluating it. To actually compute the transpose, use the <code class="docutils literal notranslate"><span class="pre">transpose()</span></code>
function, or the <code class="docutils literal notranslate"><span class="pre">.T</span></code> attribute of matrices.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Transpose</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">transpose</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Transpose</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">A.T</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">T</span> <span class="o">==</span> <span class="n">transpose</span><span class="p">(</span><span class="n">A</span><span class="p">)</span> <span class="o">==</span> <span class="n">Transpose</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Transpose</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="p">)</span>
<span class="go">(A*B).T</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">transpose</span><span class="p">(</span><span class="n">A</span><span class="o">*</span><span class="n">B</span><span class="p">)</span>
<span class="go">B.T*A.T</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.Trace">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">Trace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mat</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/trace.py#L6-L140"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.Trace" title="Permalink to this definition">¶</a></dt>
<dd><p>Matrix Trace</p>
<p>Represents the trace of a matrix expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">Trace</span><span class="p">,</span> <span class="n">eye</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Trace</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="go">Trace(A)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Trace</span><span class="p">(</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">Trace(Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Trace</span><span class="p">(</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">simplify</span><span class="p">()</span>
<span class="go">3</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.FunctionMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">FunctionMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rows</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cols</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lamda</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/funcmatrix.py#L9-L118"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.FunctionMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a matrix using a function (<code class="docutils literal notranslate"><span class="pre">Lambda</span></code>) which gives
outputs according to the coordinates of each matrix entries.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rows</strong> : nonnegative integer. Can be symbolic.</p>
<p><strong>cols</strong> : nonnegative integer. Can be symbolic.</p>
<p><strong>lamda</strong> : Function, Lambda or str</p>
<blockquote>
<div><p>If it is a SymPy <code class="docutils literal notranslate"><span class="pre">Function</span></code> or <code class="docutils literal notranslate"><span class="pre">Lambda</span></code> instance,
it should be able to accept two arguments which represents the
matrix coordinates.</p>
<p>If it is a pure string containing python <code class="docutils literal notranslate"><span class="pre">lambda</span></code> semantics,
it is interpreted by the SymPy parser and casted into a SymPy
<code class="docutils literal notranslate"><span class="pre">Lambda</span></code> instance.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Creating a <code class="docutils literal notranslate"><span class="pre">FunctionMatrix</span></code> from <code class="docutils literal notranslate"><span class="pre">Lambda</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">FunctionMatrix</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">,</span> <span class="n">MatPow</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;i,j,n,m&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">FunctionMatrix</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">),</span> <span class="n">i</span> <span class="o">+</span> <span class="n">j</span><span class="p">))</span>
<span class="go">FunctionMatrix(n, m, Lambda((i, j), i + j))</span>
</pre></div>
</div>
<p>Creating a <code class="docutils literal notranslate"><span class="pre">FunctionMatrix</span></code> from a sympy function:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">KroneckerDelta</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">FunctionMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">KroneckerDelta</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[1, 0, 0],</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1]])</span>
</pre></div>
</div>
<p>Creating a <code class="docutils literal notranslate"><span class="pre">FunctionMatrix</span></code> from a sympy undefined function:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">FunctionMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[f(0, 0), f(0, 1), f(0, 2)],</span>
<span class="go">[f(1, 0), f(1, 1), f(1, 2)],</span>
<span class="go">[f(2, 0), f(2, 1), f(2, 2)]])</span>
</pre></div>
</div>
<p>Creating a <code class="docutils literal notranslate"><span class="pre">FunctionMatrix</span></code> from python <code class="docutils literal notranslate"><span class="pre">lambda</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">FunctionMatrix</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="s1">&#39;lambda i, j: i + j&#39;</span><span class="p">)</span>
<span class="go">FunctionMatrix(n, m, Lambda((i, j), i + j))</span>
</pre></div>
</div>
<p>Example of lazy evaluation of matrix product:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">FunctionMatrix</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">1000</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">),</span> <span class="n">i</span> <span class="o">+</span> <span class="n">j</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">Y</span><span class="o">*</span><span class="n">Y</span><span class="p">,</span> <span class="n">MatPow</span><span class="p">)</span> <span class="c1"># this is an expression object</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">Y</span><span class="o">**</span><span class="mi">2</span><span class="p">)[</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="p">]</span> <span class="c1"># So this is evaluated lazily</span>
<span class="go">342923500</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>This class provides an alternative way to represent an extremely
dense matrix with entries in some form of a sequence, in a most
sparse way.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.PermutationMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">PermutationMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">perm</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/permutation.py#L9-L165"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.PermutationMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>A Permutation Matrix</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>perm</strong> : Permutation</p>
<blockquote>
<div><p>The permutation the matrix uses.</p>
<p>The size of the permutation determines the matrix size.</p>
<p>See the documentation of
<a class="reference internal" href="../combinatorics/permutations.html#sympy.combinatorics.permutations.Permutation" title="sympy.combinatorics.permutations.Permutation"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.combinatorics.permutations.Permutation</span></code></a> for
the further information of how to create a permutation object.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">PermutationMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
</pre></div>
</div>
<p>Creating a permutation matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">PermutationMatrix</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">Matrix([</span>
<span class="go">[0, 1, 0],</span>
<span class="go">[0, 0, 1],</span>
<span class="go">[1, 0, 0]])</span>
</pre></div>
</div>
<p>Permuting a matrix row and column:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="n">P</span><span class="o">*</span><span class="n">M</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1],</span>
<span class="go">[2],</span>
<span class="go">[0]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">P</span><span class="p">)</span>
<span class="go">Matrix([[2, 0, 1]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../combinatorics/permutations.html#sympy.combinatorics.permutations.Permutation" title="sympy.combinatorics.permutations.Permutation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.combinatorics.permutations.Permutation</span></code></a></p>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixPermute">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatrixPermute</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mat</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perm</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">axis</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/permutation.py#L168-L303"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixPermute" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbolic representation for permuting matrix rows or columns.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>perm</strong> : Permutation, PermutationMatrix</p>
<blockquote>
<div><p>The permutation to use for permuting the matrix.
The permutation can be resized to the suitable one,</p>
</div></blockquote>
<p><strong>axis</strong> : 0 or 1</p>
<blockquote>
<div><p>The axis to permute alongside.
If <span class="math notranslate nohighlight">\(0\)</span>, it will permute the matrix rows.
If <span class="math notranslate nohighlight">\(1\)</span>, it will permute the matrix columns.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>This follows the same notation used in
<a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.permute" title="sympy.matrices.common.MatrixCommon.permute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sympy.matrices.common.MatrixCommon.permute()</span></code></a>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixPermute</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
</pre></div>
</div>
<p>Permuting the matrix rows:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixPermute</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[4, 5, 6],</span>
<span class="go">[7, 8, 9],</span>
<span class="go">[1, 2, 3]])</span>
</pre></div>
</div>
<p>Permuting the matrix columns:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixPermute</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">as_explicit</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[2, 3, 1],</span>
<span class="go">[5, 6, 4],</span>
<span class="go">[8, 9, 7]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="common.html#sympy.matrices.common.MatrixCommon.permute" title="sympy.matrices.common.MatrixCommon.permute"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.common.MatrixCommon.permute</span></code></a></p>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.Identity">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">Identity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/special.py#L98-L159"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.Identity" title="Permalink to this definition">¶</a></dt>
<dd><p>The Matrix Identity I - multiplicative identity</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">Identity</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">Identity</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">I</span><span class="o">*</span><span class="n">A</span>
<span class="go">A</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.ZeroMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">ZeroMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/special.py#L10-L59"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.ZeroMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>The Matrix Zero 0 - additive identity</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">ZeroMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">ZeroMatrix</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">+</span> <span class="n">Z</span>
<span class="go">A</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span><span class="o">*</span><span class="n">A</span><span class="o">.</span><span class="n">T</span>
<span class="go">0</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.CompanionMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">CompanionMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">poly</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/companion.py#L8-L56"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.CompanionMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>A symbolic companion matrix of a polynomial.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Poly</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices.expressions</span> <span class="kn">import</span> <span class="n">CompanionMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c0</span><span class="p">,</span> <span class="n">c1</span><span class="p">,</span> <span class="n">c2</span><span class="p">,</span> <span class="n">c3</span><span class="p">,</span> <span class="n">c4</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;c0:5&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Poly</span><span class="p">(</span><span class="n">c0</span> <span class="o">+</span> <span class="n">c1</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">c2</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">c3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> <span class="n">c4</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">4</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">5</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">CompanionMatrix</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">CompanionMatrix(Poly(x**5 + c4*x**4 + c3*x**3 + c2*x**2 + c1*x + c0,</span>
<span class="go">x, domain=&#39;ZZ[c0,c1,c2,c3,c4]&#39;))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.MatrixSet">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.</span></span><span class="sig-name descname"><span class="pre">MatrixSet</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">set</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/sets.py#L7-L62"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.MatrixSet" title="Permalink to this definition">¶</a></dt>
<dd><p>MatrixSet represents the set of matrices with <code class="docutils literal notranslate"><span class="pre">shape</span> <span class="pre">=</span> <span class="pre">(n,</span> <span class="pre">m)</span></code> over the
given set.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">MatrixSet</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span><span class="p">,</span> <span class="n">I</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">MatrixSet</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nb">set</span><span class="o">=</span><span class="n">S</span><span class="o">.</span><span class="n">Reals</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="ow">in</span> <span class="n">M</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="n">I</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="ow">in</span> <span class="n">M</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="block-matrices">
<h2>Block Matrices<a class="headerlink" href="#block-matrices" title="Permalink to this headline">¶</a></h2>
<p>Block matrices allow you to construct larger matrices out of smaller
sub-blocks. They can work with <a class="reference internal" href="#sympy.matrices.expressions.MatrixExpr" title="sympy.matrices.expressions.MatrixExpr"><code class="xref py py-class docutils literal notranslate"><span class="pre">MatrixExpr</span></code></a> or
<a class="reference internal" href="immutablematrices.html#sympy.matrices.immutable.ImmutableMatrix" title="sympy.matrices.immutable.ImmutableMatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ImmutableMatrix</span></code></a> objects.</p>
<span class="target" id="module-sympy.matrices.expressions.blockmatrix"></span><dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.blockmatrix.</span></span><span class="sig-name descname"><span class="pre">BlockMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L23-L551"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>A BlockMatrix is a Matrix comprised of other matrices.</p>
<p>The submatrices are stored in a SymPy Matrix object but accessed as part of
a Matrix Expression</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="p">(</span><span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">Identity</span><span class="p">,</span> <span class="n">ZeroMatrix</span><span class="p">,</span> <span class="n">block_collapse</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">l</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n m l&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">m</span> <span class="p">,</span><span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">X</span><span class="p">,</span> <span class="n">Z</span><span class="p">],</span> <span class="p">[</span><span class="n">ZeroMatrix</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">),</span> <span class="n">Y</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[X, Z],</span>
<span class="go">[0, Y]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">Identity</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="n">Z</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">C</span><span class="p">)</span>
<span class="go">Matrix([[I, Z]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">block_collapse</span><span class="p">(</span><span class="n">C</span><span class="o">*</span><span class="n">B</span><span class="p">))</span>
<span class="go">Matrix([[X, Z + Z*Y]])</span>
</pre></div>
</div>
<p>Some matrices might be comprised of rows of blocks with
the matrices in each row having the same height and the
rows all having the same total number of columns but
not having the same number of columns for each matrix
in each row. In this case, the matrix is not a block
matrix and should be instantiated by Matrix.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">ones</span><span class="p">,</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dat</span> <span class="o">=</span> <span class="p">[</span>
<span class="gp">... </span><span class="p">[</span><span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="n">ones</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span><span class="o">*</span><span class="mi">3</span><span class="p">,</span> <span class="n">ones</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="mi">4</span><span class="p">]]</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">BlockMatrix</span><span class="p">(</span><span class="n">dat</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>:
<span class="go">Although this matrix is comprised of blocks, the blocks do not fill</span>
<span class="go">the matrix in a size-symmetric fashion. To create a full matrix from</span>
<span class="go">these arguments, pass them directly to Matrix.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Matrix</span><span class="p">(</span><span class="n">dat</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1, 1, 2, 2, 2],</span>
<span class="go">[1, 1, 2, 2, 2],</span>
<span class="go">[1, 1, 2, 2, 2],</span>
<span class="go">[3, 3, 3, 4, 4],</span>
<span class="go">[3, 3, 3, 4, 4]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="matrices.html#sympy.matrices.matrices.MatrixBase.irregular" title="sympy.matrices.matrices.MatrixBase.irregular"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.irregular</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition">
<span class="sig-name descname"><span class="pre">LDUdecomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L330-L388"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Block LDU decomposition of
a 2x2 Block Matrix</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><strong>(L, D, U)</strong> : Matrices</p>
<blockquote>
<div><p>L : Lower Diagonal Matrix
D : Diagonal Matrix
U : Upper Diagonal Matrix</p>
</div></blockquote>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ShapeError</strong></p>
<blockquote>
<div><p>If the block matrix is not a 2x2 matrix</p>
</div></blockquote>
<p><strong>NonInvertibleMatrixError</strong></p>
<blockquote>
<div><p>If the matrix “A” is non-invertible</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span><span class="p">,</span> <span class="n">block_collapse</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;m n&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">],</span> <span class="p">[</span><span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">U</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">LDUdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">block_collapse</span><span class="p">(</span><span class="n">L</span><span class="o">*</span><span class="n">D</span><span class="o">*</span><span class="n">U</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[A, B],</span>
<span class="go">[C, D]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition" title="sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition" title="sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition">
<span class="sig-name descname"><span class="pre">LUdecomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L450-L506"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Block LU decomposition of
a 2x2 Block Matrix</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><strong>(L, U)</strong> : Matrices</p>
<blockquote>
<div><p>L : Lower Diagonal Matrix
U : Upper Diagonal Matrix</p>
</div></blockquote>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ShapeError</strong></p>
<blockquote>
<div><p>If the block matrix is not a 2x2 matrix</p>
</div></blockquote>
<p><strong>NonInvertibleMatrixError</strong></p>
<blockquote>
<div><p>If the matrix “A” is non-invertible</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span><span class="p">,</span> <span class="n">block_collapse</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;m n&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">],</span> <span class="p">[</span><span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="p">,</span> <span class="n">U</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">LUdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">block_collapse</span><span class="p">(</span><span class="n">L</span><span class="o">*</span><span class="n">U</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[A, B],</span>
<span class="go">[C, D]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition" title="sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition" title="sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition">
<span class="sig-name descname"><span class="pre">UDLdecomposition</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L390-L448"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.UDLdecomposition" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Block UDL decomposition of
a 2x2 Block Matrix</p>
<dl class="field-list">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><strong>(U, D, L)</strong> : Matrices</p>
<blockquote>
<div><p>U : Upper Diagonal Matrix
D : Diagonal Matrix
L : Lower Diagonal Matrix</p>
</div></blockquote>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ShapeError</strong></p>
<blockquote>
<div><p>If the block matrix is not a 2x2 matrix</p>
</div></blockquote>
<p><strong>NonInvertibleMatrixError</strong></p>
<blockquote>
<div><p>If the matrix “D” is non-invertible</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span><span class="p">,</span> <span class="n">block_collapse</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;m n&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">],</span> <span class="p">[</span><span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">U</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">L</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">UDLdecomposition</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">block_collapse</span><span class="p">(</span><span class="n">U</span><span class="o">*</span><span class="n">D</span><span class="o">*</span><span class="n">L</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[A, B],</span>
<span class="go">[C, D]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition" title="sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.expressions.blockmatrix.BlockMatrix.LDUdecomposition</span></code></a>, <a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition" title="sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.expressions.blockmatrix.BlockMatrix.LUdecomposition</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockMatrix.schur">
<span class="sig-name descname"><span class="pre">schur</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mat</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'A'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">generalized</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L239-L328"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.schur" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the Schur Complement of the 2x2 BlockMatrix</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>mat</strong> : String, optional</p>
<blockquote>
<div><p>The matrix with respect to which the
Schur Complement is calculated. ‘A’ is
used by default</p>
</div></blockquote>
<p><strong>generalized</strong> : bool, optional</p>
<blockquote>
<div><p>If True, returns the generalized Schur
Component which uses Moore-Penrose Inverse</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>M</strong> : Matrix</p>
<blockquote>
<div><p>The Schur Complement Matrix</p>
</div></blockquote>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>ShapeError</strong></p>
<blockquote>
<div><p>If the block matrix is not a 2x2 matrix</p>
</div></blockquote>
<p><strong>NonInvertibleMatrixError</strong></p>
<blockquote>
<div><p>If given matrix is non-invertible</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;m n&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">D</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">],</span> <span class="p">[</span><span class="n">C</span><span class="p">,</span> <span class="n">D</span><span class="p">]])</span>
</pre></div>
</div>
<p>The default Schur Complement is evaluated with “A”</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">schur</span><span class="p">()</span>
<span class="go">-C*A**(-1)*B + D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">schur</span><span class="p">(</span><span class="s1">&#39;D&#39;</span><span class="p">)</span>
<span class="go">A - B*D**(-1)*C</span>
</pre></div>
</div>
<p>Schur complement with non-invertible matrices is not
defined. Instead, the generalized Schur complement can
be calculated which uses the Moore-Penrose Inverse. To
achieve this, <span class="math notranslate nohighlight">\(generalized\)</span> must be set to <span class="math notranslate nohighlight">\(True\)</span></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">schur</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="n">generalized</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">C - D*(B.T*B)**(-1)*B.T*A</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="o">.</span><span class="n">schur</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="n">generalized</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">-A*(C.T*C)**(-1)*C.T*D + B</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="matrices.html#sympy.matrices.matrices.MatrixBase.pinv" title="sympy.matrices.matrices.MatrixBase.pinv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.matrices.MatrixBase.pinv</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r524"><span class="brackets"><a class="fn-backref" href="#id1">R524</a></span></dt>
<dd><p>Wikipedia Article on Schur Component : <a class="reference external" href="https://en.wikipedia.org/wiki/Schur_complement">https://en.wikipedia.org/wiki/Schur_complement</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockMatrix.transpose">
<span class="sig-name descname"><span class="pre">transpose</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L216-L237"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockMatrix.transpose" title="Permalink to this definition">¶</a></dt>
<dd><p>Return transpose of matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span><span class="p">,</span> <span class="n">ZeroMatrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">m</span> <span class="p">,</span><span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">X</span><span class="p">,</span> <span class="n">Z</span><span class="p">],</span> <span class="p">[</span><span class="n">ZeroMatrix</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">),</span> <span class="n">Y</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[X.T,  0],</span>
<span class="go">[Z.T, Y.T]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[X, Z],</span>
<span class="go">[0, Y]])</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockDiagMatrix">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.blockmatrix.</span></span><span class="sig-name descname"><span class="pre">BlockDiagMatrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">mats</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L554-L674"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockDiagMatrix" title="Permalink to this definition">¶</a></dt>
<dd><p>A sparse matrix with block matrices along its diagonals</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockDiagMatrix</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">l</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n m l&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">m</span> <span class="p">,</span><span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">BlockDiagMatrix</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[X, 0],</span>
<span class="go">[0, Y]])</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>If you want to get the individual diagonal blocks, use
<a class="reference internal" href="#sympy.matrices.expressions.blockmatrix.BlockDiagMatrix.get_diag_blocks" title="sympy.matrices.expressions.blockmatrix.BlockDiagMatrix.get_diag_blocks"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_diag_blocks()</span></code></a>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="matrices.html#sympy.matrices.dense.diag" title="sympy.matrices.dense.diag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.matrices.dense.diag</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.BlockDiagMatrix.get_diag_blocks">
<span class="sig-name descname"><span class="pre">get_diag_blocks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L650-L674"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.BlockDiagMatrix.get_diag_blocks" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the list of diagonal blocks of the matrix.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.matrices</span> <span class="kn">import</span> <span class="n">BlockDiagMatrix</span><span class="p">,</span> <span class="n">Matrix</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">BlockDiagMatrix</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">)</span>
</pre></div>
</div>
<p>How to get diagonal blocks from the block diagonal matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">diag_blocks</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">get_diag_blocks</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diag_blocks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">Matrix([</span>
<span class="go">[1, 2],</span>
<span class="go">[3, 4]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">diag_blocks</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">Matrix([</span>
<span class="go">[5, 6],</span>
<span class="go">[7, 8]])</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.matrices.expressions.blockmatrix.block_collapse">
<span class="sig-prename descclassname"><span class="pre">sympy.matrices.expressions.blockmatrix.</span></span><span class="sig-name descname"><span class="pre">block_collapse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/matrices/expressions/blockmatrix.py#L677-L727"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.matrices.expressions.blockmatrix.block_collapse" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates a block matrix expression</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">MatrixSymbol</span><span class="p">,</span> <span class="n">BlockMatrix</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span>                           <span class="n">Identity</span><span class="p">,</span> <span class="n">ZeroMatrix</span><span class="p">,</span> <span class="n">block_collapse</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">l</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n m l&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Y</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="n">m</span> <span class="p">,</span><span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Z</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">X</span><span class="p">,</span> <span class="n">Z</span><span class="p">],</span> <span class="p">[</span><span class="n">ZeroMatrix</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">),</span> <span class="n">Y</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[X, Z],</span>
<span class="go">[0, Y]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">BlockMatrix</span><span class="p">([[</span><span class="n">Identity</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="n">Z</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">C</span><span class="p">)</span>
<span class="go">Matrix([[I, Z]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">block_collapse</span><span class="p">(</span><span class="n">C</span><span class="o">*</span><span class="n">B</span><span class="p">))</span>
<span class="go">Matrix([[X, Z + Z*Y]])</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Matrix Expressions</a><ul>
<li><a class="reference internal" href="#matrix-expressions-core-reference">Matrix Expressions Core Reference</a></li>
<li><a class="reference internal" href="#block-matrices">Block Matrices</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="immutablematrices.html"
                        title="previous chapter">Immutable Matrices</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../ntheory.html"
                        title="next chapter">Number Theory</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/matrices/expressions.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../ntheory.html" title="Number Theory"
             >next</a> |</li>
        <li class="right" >
          <a href="immutablematrices.html" title="Immutable Matrices"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Matrices</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Matrix Expressions</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/matrices/expressions.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:19 GMT -->
</html>